﻿using System;

namespace SystemX.Cache
{
    [Serializable]
    public class CachedItem
    {
        #region properties
        /// <summary>
        /// the identifier of the cached data item
        /// </summary>
        public string Key { get; set; }
        /// <summary>
        /// the value of the cached data item
        /// </summary>
        public object Item { get; set; }
        /// <summary>
        /// The time at which the item expires and can be removed from the cache.
        /// </summary>
        public DateTime AbsoluteExpiration { get; set; }

        /// <summary>
        /// The interval between the time the item is last accessed and when that item expires.
        /// </summary>
        public TimeSpan SlidingExpiration { get; set; }
        #endregion

        #region .ctor
        /// <summary>
        /// Initializes a new instance of the <b>CachedItem</b> class.
        /// </summary>
        /// <remarks>This contructor is intended for serialization purposes only.</remarks>
        public CachedItem()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <b>CachedItem</b> class.
        /// </summary>
        /// <param name="key">The identifier of the item.</param>
        /// <param name="item">The value of the item.</param>
        /// <param name="absoluteExpiration">The time at which the item expires and can be removed from the cache.</param>
        /// <param name="slidingExpiration">The interval between the time the item is last accessed and when that item expires.</param>
        public CachedItem(string key, object item, DateTime absoluteExpiration, TimeSpan slidingExpiration)
        {
            Key = key;
            Item = item;
            AbsoluteExpiration = absoluteExpiration;
            SlidingExpiration = slidingExpiration;
        }
        #endregion
    }
}
